//
//  NetError.m
//  CarCare
//
//  Created by ileo on 14-9-25.
//  Copyright (c) 2014年 baozun. All rights reserved.
//

#import "NetDealMgr.h"
#import "ScreenMgr.h"
#import "AIUserInfo.h"
#import "EncryptMgr.h"

@implementation NetDealMgr

+(void)dealWithNetError:(NET_ERROR)error doThis:(void (^)())doSomething{
    switch (error) {
        case NET_ERROR_SESSION:
            if (USERINFO.isLogin) {
                [SCREEN changeToLoginScreen];
                [AlertMgr showShortWarnTextTips:@[@"请重新登录"]];
            }
            break;
        case NET_ERROR_SIGN:
            if (USERINFO.isLogin) {
                [SCREEN changeToLoginScreen];
                [AlertMgr showShortWarnTextTips:@[@"请重新登录"]];
            }
            break;
        case NET_ERROR_LINK:
            break;
        default:
            break;
    }
    if (doSomething) {
        doSomething();
    }
}

+(NSString *)errorTips:(NET_ERROR)error{
    NSString *key = [NSString stringWithFormat:@"net_error_%zd",error];
    return LOCSTRING(key);
}

+(NSDictionary *)paramsAddSignWithParams:(NSDictionary *)oldParams{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:oldParams];
    [params setObject:[EncryptMgr encryptWithString:[EncryptMgr sortAndSpliceWithParams:params]] forKey:@"sign"];
    return params;
}

@end